﻿using System;
using System.Collections;
using System.Configuration;
using System.Data; 
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls; 
using System.Web.UI.HtmlControls;
using Runda.CMS.Bll;
using Runda.CMS.Common.Entity;
using System.Collections.Generic;
using Telerik.WebControls; 

namespace Runda.CMS.Portal.NoticeManage
{
    public partial class SelectDutyUser : BasePage
    {
        public override bool IsCheckAccessible
        {
            get
            {
                return false;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void btnQuery_Click(object sender, EventArgs e)
        {
            string WhereClause = "";
            if (txtUserName.Text .Trim() != "")
            {
                WhereClause = " and UserName like '%"+txtUserName.Text.Trim()+"%'";
            }
            List<SysUserEntity> Users = new SystemBll().GetAll<SysUserEntity>(WhereClause, " Order By CreatedOn asc");
            gridUsers.DataSource = Users;
            gridUsers.DataBind();
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            ContractBll bll = new ContractBll();
            foreach (GridDataItem item in gridUsers.Items)
            {
                CheckBox cbxSelect = item.FindControl("cbxSelect") as CheckBox;
                if (cbxSelect != null)
                {
                    if (cbxSelect.Checked)
                    {
                        Guid UserID = new Guid(item.GetDataKeyValue("UserID").ToString());
                        SysDutyGroupUserEntity entity = bll.Get<SysDutyGroupUserEntity>(" and DutyGroupID = '" + Request.QueryString["DutyGroupID"] + "' and UserID = '" + UserID + "'");
                        if (entity == null)
                        {
                            entity = new SysDutyGroupUserEntity();
                            entity.DutyGroupID = new Guid(Request.QueryString["DutyGroupID"]);
                            entity.UserID = UserID;
                            entity.UserName = ((Label)item.FindControl("lblUserName")).Text;
                            entity.Deleted = false;

                            bll.Insert(entity);
                        }
                    }
                }
            }

            ClientScript.RegisterStartupScript(this.GetType(), "success", "window.close();", true);

        }
    }
}
